package com.erlang.springbootinit.controller;

import com.erlang.springbootinit.entity.Customer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by IntelliJ IDEA.
 *
 * @author ZGQ
 */
@RestController
public class UserController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private Customer customer;

    @Autowired
    private Environment environment;

    @RequestMapping("get")
    public String get() {
        System.out.println(customer);
        for (String address : customer.getAddress()) {
            System.out.println(address);
        }
        System.out.println(environment.getProperty("Customer.username"));
        return null;
    }

    @GetMapping("log")
    public Object testLog(){

        logger.debug("---debug---debug---");
        logger.info(" ---info ---信息---");
        logger.warn(" ---warn ---警告--- ");
        logger.error("---error---错误---");
        //这也是个错误的日志级别
        int i=1/0;
        return "yes";
    }
}
